package ACWing.WeeklyRace;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author :chenjie
 * @description
 * @date :Created 2023/2/23 23:18
 */
public class WhereAmI {
    static int n;
    static String s;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        sc.nextLine();
        s = sc.nextLine();
        int l=1,r=n;
        while (l<r){
            int mid=r+l>>1;
            if(check(mid)){
                r=mid;
            }else {
                l=mid+1;
            }

        }
        System.out.println(l);
    }

    /**
     * 检查长度为mid的字符串是否出现相同的
     * @param mid
     * @return
     */
    private static boolean check(int mid) {

        Map<String, Integer> map = new HashMap<>();
        int max = 0;

        for (int i = 0; i <= n - mid; i ++){
            String t = s.substring(i, i + mid);
            if (map.get(t) == null) map.put(t, 1);
            else  map.put(t, map.get(t) + 1);
            max = Math.max(map.get(t), max);
            if (max != 1) return false;
        }

        return true;

    }

}
